package com.delivery.deliverysystem.controller;


import com.delivery.deliverysystem.common.ServerResponse;
import com.delivery.deliverysystem.pojo.DAO.ProductDAO;
import com.delivery.deliverysystem.pojo.DO.BasicImformation;
import com.delivery.deliverysystem.pojo.DO.Client;
import com.delivery.deliverysystem.pojo.DO.ProductCategory;
import com.delivery.deliverysystem.service.BasicImformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 产品类别控制类
 */
@RestController
@RequestMapping("/basicInformation")
@Api(tags = "其他资料接口")
public class BasicInformationController {
    @Autowired
    private BasicImformationService basicImformationService;

    @PostMapping("/createInformation")
    @ApiOperation(value = "新增其他资料", response = ServerResponse.class, httpMethod = "POST")
    public ServerResponse createInformation(@RequestParam int type,@RequestParam String typeCotent){
        return ServerResponse.createBySuccess(basicImformationService.createInformation(type,typeCotent));
    }
    @PostMapping("/updateInformation")
    @ApiOperation(value = "修改其他资料", response = ServerResponse.class, httpMethod = "POST")
    public ServerResponse updateInformation(@RequestParam Integer id,@RequestParam String typeCotent){
        return ServerResponse.createBySuccess(basicImformationService.updateInformation(id,typeCotent));
    }
    @PostMapping("/deleteInformation")
    @ApiOperation(value = "删除其他资料",response = ServerResponse.class,httpMethod = "POST")
    public ServerResponse deleteInformation(@RequestParam Integer id){
        boolean b = basicImformationService.removeById(id);
        if(b) return ServerResponse.createBySuccess("删除成功");
        return ServerResponse.createByError("删除失败");
    }
    @GetMapping("/getInformationById")
    @ApiOperation(value = "根据id查询其他资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getInformationById(@RequestParam Integer id){
        BasicImformation imformation = basicImformationService.getInformationById(id);
        if(imformation==null) return ServerResponse.createByError("资料不存在");
        return ServerResponse.createBySuccess(imformation);
    }
    @GetMapping("/getInformationByType")
    @ApiOperation(value = "根据类型查询其他资料",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getInformationByType(@RequestParam Integer type){
        List<BasicImformation> imformations = basicImformationService.getInformationByType(type);
        if(imformations==null) return ServerResponse.createByError("资料不存在");
        return ServerResponse.createBySuccess(imformations);
    }
    @GetMapping("/getInformationList")
    @ApiOperation(value = "获取全部产品类别",response = ServerResponse.class,httpMethod = "GET")
    public ServerResponse getCategoryList(){
        List<BasicImformation> imformations = basicImformationService.getCategoryList();
        if(imformations!=null && !imformations.isEmpty()) return ServerResponse.createBySuccess(imformations);
        return ServerResponse.createBySuccess("资料列表为空");
    }
}
